package lsysteem;

public class LSNode
{
	public char value;
	public LSNode next;
	
	public LSNode(){
		
	}
	
	public LSNode(char value){
		this.value = value;
		this.next = null;
	}
	
	public LSNode clone()
	{
		LSNode item = new LSNode();
		item.value = value;
		//if(next != null) item.next = next.clone();
		LSNode _currentItem = this;
		LSNode _newItemCurrent = item;
		while (_currentItem.next != null){
			_newItemCurrent.next = new LSNode();
			_newItemCurrent.next.value = _currentItem.next.value;
			_currentItem = _currentItem.next;
			_newItemCurrent = _newItemCurrent.next;
		}
		return item;
	}
	
	public void appendLast(LSNode l)
	{
		LSNode _currentItem = this;
		while (_currentItem.next != null){
			_currentItem = _currentItem.next;
		}
		_currentItem.next = l;
		/*if(next != null)
		{
			next.appendLast(l);
		}
		else
		{
			next = l;
		}*/
	}
	
	public String toString()
	{
		String result = "";
		LSNode _currentItem = this;
		while (_currentItem.next != null){
			result += _currentItem.value;
			_currentItem = _currentItem.next;
		}
		return result;
		//return ""+value+""+(next != null?next.toString():"")+"";
		//return "error";
	}
}
